#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>

int main(int argc, char const *argv[])
{
    printf("主线程(%d)开始执行...\n", getpid());
    pid_t pid = fork();
    int num = 6;
    if (pid == -1)
    {
        printf("子进程创建失败了。\n");
        return -1;
    }
    else if (pid == 0)
    {
        num = 7;
        printf("子进程(%d)开始执行, 父进程id=%d, num=%d, num地址=%p...\n", getpid(), getppid(), num, &num);
    }
    else
    {
        num = 8;
        printf("父进程(%d)继续执行, 子进程id=%d, num=%d, num地址=%p...\n", getpid(), pid, num, &num);
        
    }
    printf("进程(%d)执行结束。\n", getpid());
    return 0;
}
